#import "UIControl+LCTrack.h"
#import "NSObject+LCSwizzle.h"
#import "LCAutoTrackManager.h"
#import "UIControl+LCTrackID.h"

@implementation UIControl (LCTrack)

+ (void)lc_swizzleSendAction {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self lc_swizzleInstanceMethod:@selector(sendAction:to:forEvent:)
                                   with:@selector(lc_sendAction:to:forEvent:)];
    });
}

- (void)lc_sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event {
    [self lc_sendAction:action to:target forEvent:event];

    NSString *trackID = self.lc_trackID ?: @"";
    NSString *trackName = self.lc_trackName ?: @"";
    NSString *className = NSStringFromClass([self class]);

    [LCAutoTrackManager trackEventWithName:@"control_click"
                                     params:@{
                                         @"control": className,
                                         @"trackID": trackID,
                                         @"trackName": trackName
                                     }];
}

@end